package com.djinfo.work.util.quartz;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
//import org.quartz.JobBuilder.*;
//import org.quartz.TriggerBuilder.*;
//import org.quartz.Trigger;
//import org.quartz.SimpleScheduleBuilder.*;

public class QuartzTest {

    public static void main(String[] args) {
        try {

            // Grab the Scheduler instance from the Factory
            Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

            // define the job and tie it to our HelloJob class
            JobDetail job = JobBuilder.newJob(JobTest.class)
                    .withIdentity("job1", "group1").build();

            // Trigger the job to run now, and then repeat every 2 seconds
            Trigger trigger = TriggerBuilder
                    .newTrigger()
                    .withIdentity("trigger1", "group1")
                    .startNow()
                    .withSchedule(
                            SimpleScheduleBuilder.simpleSchedule()
                                    .withIntervalInSeconds(2).repeatForever())
                    .build();

            // Tell quartz to schedule the job using our trigger
            scheduler.scheduleJob(job, trigger);
            // and start it off
            scheduler.start();
            // mail thread sleep 2 seconds
            //System.out.println(Thread.currentThread().getName());
            Thread.sleep(30 * 1000);
            scheduler.shutdown();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SchedulerException se) {
            se.printStackTrace();
        }
    }
}
